home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWArchiv / Include / FWArOper.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-21  |  2.8 KB  |  89 lines  |  [TEXT/MPS ]

  1. #ifndef FWAROPER_H
  2. #define FWAROPER_H
  3. //========================================================================================
  4. //
  5. //    File:                FWArOper.h
  6. //    Release Version:    $ 1.0d1 $
  7. //
  8. //    Creation Date:        3/28/94
  9. //
  10. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  11. //
  12. //========================================================================================
  13.  
  14. #ifndef FWARDYNA_H
  15. #include "FWArDyna.h"
  16. #endif
  17.  
  18.  
  19. //----------------------------------------------------------------------------------------
  20. // operator>>
  21. //
  22. // Global template function for reading from a readableArchive. The type 'tDynamicClass'
  23. // must be a dynamic class or a compile-time error will occur.
  24. //----------------------------------------------------------------------------------------
  25.  
  26. template <class tDynamicClass>
  27. FW_CReadableArchive & operator>>(FW_CReadableArchive & readableArchive,
  28.                                  tDynamicClass* & object)
  29. {
  30.     void * voidPtr = (void *)object;
  31.     FW_CDynamicArchiver::InputObject(readableArchive, voidPtr);
  32.     object = (tDynamicClass *)voidPtr;
  33.  
  34. #ifdef FW_DEBUG
  35.     // Cause a compile-time error if 'tDynamicClass' is a static type
  36.     tDynamicClass* debugPtr = FW_DYNAMIC_CAST(tDynamicClass, object);
  37.     
  38.     // Cause a run-time error if 'debugPtr' is 0.
  39.     FW_ASSERT(debugPtr);
  40. #endif
  41.  
  42.     return readableArchive;
  43. }
  44.  
  45. //----------------------------------------------------------------------------------------
  46. // operator>>
  47. //
  48. // Specialization for type 'char *'.
  49. //----------------------------------------------------------------------------------------
  50.  
  51. inline FW_CReadableArchive & operator>>(FW_CReadableArchive & readableArchive,
  52.                                         char *nullTerminatedString)
  53. {
  54.     ((FW_CReadableStream &)readableArchive).operator>>(nullTerminatedString);
  55.     
  56.     return readableArchive;
  57. }
  58.  
  59. //----------------------------------------------------------------------------------------
  60. // operator<<
  61. //
  62. // Global template function for writing to a writableArchive. The type 'tDynamicClass' must
  63. // must be a dynamic class or a compile-time error will occur.
  64. //----------------------------------------------------------------------------------------
  65.  
  66. template <class tDynamicClass>
  67. FW_CWritableArchive & operator<<(FW_CWritableArchive & writableArchive,
  68.                                  const tDynamicClass * object)
  69. {
  70.     FW_CDynamicArchiver::OutputObject(writableArchive, object, FW_CLASSNAME_FROM_POINTER(object));
  71.  
  72.     return writableArchive;
  73. }
  74.  
  75. //----------------------------------------------------------------------------------------
  76. // operator<<
  77. //
  78. // Specialization for type 'const char *'.
  79. //----------------------------------------------------------------------------------------
  80.  
  81. inline FW_CWritableArchive & operator<<(FW_CWritableArchive & writableArchive,
  82.                                         const char *nullTerminatedString)
  83. {
  84.     ((FW_CWritableStream &)writableArchive).operator<<(nullTerminatedString);
  85.     
  86.     return writableArchive;
  87. }
  88.  
  89. #endif